home *** CD-ROM | disk | FTP | other *** search
- /* --------------------------------------------------------------------------
- * machdep.c: Copyright (c) Mark P Jones 1991-1993. All rights reserved.
- * See goferite.h for details and conditions of use etc...
- * Gofer version 2.28 January 1993
- *
- * Machine dependent code
- * RISCOS specific code provided by Bryan Scatergood, JBS
- * ------------------------------------------------------------------------*/
-
- #if UNIX
- #include <signal.h>
- #include <sys/ioctl.h>
- #include <fcntl.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #endif
-
- #if (TURBOC | BCC)
- #include <dos.h>
- #include <conio.h>
- #include <io.h>
- #include <stdlib.h>
- #include <mem.h>
- #include <sys\stat.h>
- #include <time.h>
- extern unsigned _stklen = 8000; /* Allocate an 8k stack segment */
- #endif
-
- #if ZTC
- #include <stdlib.h>
- #include <signal.h>
- #include <fcntl.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #endif
-
- #if DJGPP
- #include <dos.h>
- #include <stdlib.h>
- #include <std.h>
- #include <signal.h>
- #include <fcntl.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #endif
-
- #if RISCOS
- #include <assert.h>
- #include <signal.h>
- #include "swis.h"
- #include "os.h"
- #endif
-
- #if MPW
- #include <stdio.h>
- #include <types.h>
- #include <memory.h>
-
- /* Replaces stat.h for the Mac */
- #include <Time.h>
- // typedef long time_t;
-
- struct stat
- {
- time_t st_mtime;
- long st_size;
- };
-
- #pragma segment Machdep
- #endif
-
- #if MAC
- #define ILLEGAL_WINDOW (-1) /* In mac.h, but we can't include that here! */
-
- #include <CursorCtl.h> /* For rotating cursors/GC cursor */
- #endif
-
-
- /* --------------------------------------------------------------------------
- * Machine dependent code is used in each of:
- * - The gofer interpreter MACHDEP_GOFER
- * - The gofer compiler MACHDEP_GOFC
- * - The compiler runtime system MACHDEP_RUNTIME
- * In many cases, the the same code is used in each part. The following
- * sections of code are enclosed in suitable #if ... #endif directives to
- * indicate which sections require particular parts of the code. Each of
- * the three systems above defines one of the three symbols on the right
- * above as 1 and then #includes this file. The following directives make
- * sure that the other macros are set to the correct defaults.
- * ------------------------------------------------------------------------*/
-
- #ifndef MACHDEP_GOFER
- #define MACHDEP_GOFER 0
- #endif
- #ifndef MACHDEP_GOFC
- #define MACHDEP_GOFC 0
- #endif
- #ifndef MACHDEP_RUNTIME
- #define MACHDEP_RUNTIME 0
- #endif
-
- /* --------------------------------------------------------------------------
- * Find information about a file:
- * ------------------------------------------------------------------------*/
-
- #if (MACHDEP_GOFER | MACHDEP_GOFC)
- #if RISCOS
- typedef struct { unsigned hi, lo; } Time;
- #define timeChanged(now,thn) (now.hi!=thn.hi || now.lo!=thn.lo)
- #define timeSet(var,tm) var.hi = tm.hi; var.lo = tm.lo
- #else
- typedef time_t Time;
- #define timeChanged(now,thn) (now!=thn)
- #define timeSet(var,tm) var = tm
- #endif
-
- static Void local getFileInfo Args((String, Time *, Long *));
-
- static Void local getFileInfo(s,tm,sz) /* find time stamp and size of file*/
- String s;
- Time *tm;
- Long *sz; {
- #if RISCOS /* get file info for RISCOS -- JBS */
- os_regset r; /* RISCOS PRM p.850 and p.837 */
- r.r[0] = 17; /* Read catalogue, no path */
- r.r[1] = (int)s;
- os_swi(OS_File, &r);
- if(r.r[0] == 1 && (r.r[2] & 0xFFF00000) == 0xFFF00000) {
- tm->hi = r.r[2] & 0xFF; /* Load address (high byte) */
- tm->lo = r.r[3]; /* Execution address (low 4 bytes) */
- }
- else /* Not found, or not time-stamped */
- tm->hi = tm->lo = 0;
- *sz = (Long)(r.r[0] == 1 ? r.r[4] : 0);
- #else /* normally just use stat() */
- static struct stat scbuf;
- stat(s,&scbuf);
- *tm = scbuf.st_mtime;
- *sz = (Long)(scbuf.st_size);
- #endif
- }
- #endif
-
- #if RISCOS /* RISCOS needs access() */
- int access(char *s, int dummy) { /* Give 1 iff cannot access file s */
- os_regset r; /* RISCOS PRM p.850 -- JBS */
- assert(dummy == 0);
- r.r[0] = 17; /* Read catalogue, no path */
- r.r[1] = (int)s;
- os_swi(OS_File, &r);
- return r.r[0] != 1;
- }
- #endif
-
- /* --------------------------------------------------------------------------
- * stat and chdir for MPW:
- * ------------------------------------------------------------------------*/
-
- #if MPW
-
- #include <Values.h>
- #include <Types.h> /* Basic type definitions */
- #include <Files.h>
- #if !THINKC
- #include <Strings.h>
- #endif
-
- stat(file,sb)
- char *file;
- struct stat *sb;
- {
- FileParam finfo;
- short volnum;
-
- GetVol(NULL,&volnum);
-
- finfo.ioCompletion = NULL;
- #if THINKC
- finfo.ioNamePtr = (StringPtr) c2pstr(file);
- #else
- finfo.ioNamePtr = c2pstr(file);
- #endif
- finfo.ioVRefNum = volnum;
- finfo.ioFVersNum = 0;
- finfo.ioFDirIndex = 0;
-
- PBGetFInfo((ParmBlkPtr)&finfo,FALSE);
-
- /* Use getfinfo to return the modification time for "file" */
- sb->st_mtime = finfo.ioFlMdDat;
- sb->st_size = finfo.ioFlLgLen;
-
- /* Now restore the string! */
- p2cstr(file);
- }
-
-
- chdir(s)
- char *s;
- {
- WDPBRec pb;
- pb.ioCompletion = NULL;
- c2pstr(s);
- pb.ioNamePtr=(StringPtr)s;
- pb.ioVRefNum = 0;
- pb.ioWDDirID = 0;
- PBHSetVol(&pb,FALSE);
- p2cstr(s);
-
- /* Check whether the directory exists */
- if(pb.ioResult == noErr)
- {
- #if MAC
- /* If so, get the volume reference and directory ID and save it */
- PBHGetVol(&pb,FALSE);
- savedir(pb.ioVRefNum,pb.ioWDDirID,FALSE);
- #endif
- return(0);
- }
- else
- return(1);
- }
- #endif
-
-
- /* --------------------------------------------------------------------------
- * Get time/date stamp for inclusion in compiled files:
- * ------------------------------------------------------------------------*/
-
- #if MACHDEP_GOFC
- #include <time.h>
- String timeString() { /* return time&date string */
- time_t clock; /* must end with '\n' character */
- time(&clock);
- return(ctime(&clock));
- }
- #endif
-
- /* --------------------------------------------------------------------------
- * Garbage collection notification:
- * ------------------------------------------------------------------------*/
-
- #if (MACHDEP_GOFER |